package log

import (
	"log"
	"os"
)

type FileWriter struct {
	path  string
}

func (w *FileWriter) Write(p []byte) (n int, err error) {
	file, err := os.OpenFile(w.path, os.O_APPEND|os.O_CREATE, 666)
	if err != nil {
		log.Fatalln("fail to create test.log file!")
	}
	defer func() {
		_ = file.Close()
	}()
	return file.Write(p)
}

func NewFileWriter(path string) *FileWriter {
	return &FileWriter{
		path:path,
	}
}
